﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Shop_of_Cl.Logic
{
    class Main
    {
        private List<Products> things = new List<Products>();
        private List<Workers> personals = new List<Workers>();
        private List<String> categories = new List<String>();
        private double Balance;
        private int procent;

        public Main()
        {
            
        }

        public void AddPersonal(string name, string surname, string position, int pay)
        {
            Workers tempWorkers = new Workers(name, surname, position, pay);
            personals.Add(tempWorkers);  //добавление в коллекцию
        }

        public void AddThing(string nameOfProduct, double costOfProduct, string season, string country,
                        string forPerson, int period, int size, int procent,int index)
        {
            Products tempThings = new Products(nameOfProduct, costOfProduct, season, country,
                        forPerson, period, size, procent,index);
            things.Add(tempThings); //добавление в коллекцию
        }

        /// <summary>
        /// Сохранение данных
        /// </summary>
        public void SaveData()
        {
            Data.Save(personals, "personals"); // Сериализация 
            Data.Save(things, "things");
            Data.Save(categories, "categories");
        }

        public void LoadData()
        {
            try
            {
                personals = (List<Workers>)Data.Load("personals");
                things = (List<Products>)Data.Load("things");
                categories = (List<String>)Data.Load("categories");
            } catch(Exception e)
            {
                MessageBox.Show("Отсутствует файл записи " + e.Message);
            }

        }

        public String ViewPersonal(int idPersonal)
        {
            try
            {
                String temp;
                temp = personals[idPersonal].Name + " " + personals[idPersonal].Surname + " " + personals[idPersonal].Position + " " + personals[idPersonal].Pay;
                return temp;
            }
            catch (ArgumentOutOfRangeException e)
            {
                return "Такой работник отсутвтвует!";
            }
        }

        public String ViewThing(int idThing)
        {
            try
            {
                return things[idThing].id+" "+things[idThing]._NameOfProduct + " " + things[idThing]._Season + " " + things[idThing]._CostOfProduct;
            }
            catch (ArgumentOutOfRangeException e)
            {
                return "Такой товар отсутвтвует!";
            }
        }

        public void DeleteCategorie(string nameCategorie)
        {
            for (int i = 0; i < categories.Count; i++)
            {
                if (nameCategorie == categories[i])
                {
                    categories.RemoveAt(i);
                    return;
                }
            }
                
              

        }

        public void ChangeProcent(int _procent)
        {
            procent = _procent;           
        }

        public void AddCategories(string nameOfCategories)
        {
            categories.Add(nameOfCategories);
        }

        public String ViewCategories(int idCategories)
        {
            return categories[idCategories];
        }

        public void Sold()
        {
            
        }

        public int CoutThingh()
        {
            return things.Count;
        }

        public double _Balance()
        {
            return Balance;
        }

        public int CountPersonal()
        {
            return personals.Count;
        }

        public int CountCategories()
        {
            return categories.Count;
        }
    }
}
